<?php

namespace Tiger\Api\Controllers;
use Dingo\Api\Routing\Helpers;
use Illuminate\Routing\Controller;
use Tiger\Api\Traits\ValidatorTrait;
/**
 * Created by PhpStorm.
 * User: pc
 * Date: 2017/4/11
 * Time: 10:45
 */
class BaseApiController extends Controller
{
    use Helpers;
    use ValidatorTrait;

    /*
 * error resposne
 * @param message
 * @param status
 */

    protected function errorResponse($message = "不能为空", $status = 406) {

        $response = array(
            'error' => $message,
            'status_code' => $status,
        );
        return response()->json($response);//返回的json格式的错误信息  数组
    }

    /*
     * success response
     * @param message
     * @param status
     */

    protected function successResponse($message = "请求成功", $status = 200) {
        $response = array(
            'message' => $message,
            'status_code' => $status,
        );
        return response()->json($response);
    }


    /**
     * Return a 406 internal server error.
     *
     * @param string $message
     *
     * @throws \Symfony\Component\HttpKernel\Exception\HttpException
     *
     * @return void
     */
    public function errorValidator($message = '参数校验错误')
    {
        $this->response->error($message, 406);
    }

}